<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
/*ini_set("memory_limit", "200M");
  mysql_connect("host=localhost dbname=devildark_a  user=root  password=root")
   or die('Could not connect:'.mysql_last_error());
*/
$db_name="devildark";  
 
$table_name="devildark_a";  
 
$connection= @mysql_connect("localhost","root","root") or die(mysql_error());  
 
$db= @mysql_select_db($db_name,$connection) or die (mysql_error());  
 
$logdate =  mysql_query("SELECT DISTINCT date FROM `devildark_a_a`");



     // p1等级分布 (1,2,....)
    $date = array('1' => array($p1date1Count, $date1), array($p1date2Count, $date2), array($p1date3Count, $date3), array($p1date4Count, $date4), array($p1date5Count, $date5), array($p1date6Count, $date6), array($p1date7Count, $date7), array($p1date8Count, $date8), array($p1date9Count, $date9), array($p1date10Count, $date10), array($p1date11Count, $date11), array($p1date12Count, $date12), array($p1date13Count, $date13), array($p1date14Count, $date14), array($p1date15Count, $date15), array($p1date16Count, $date16), array($p1date17Count, $date17), array($p1date18Count, $date18), array($p1date19Count, $date19), array($p1date20Count, $date20), array($p1date21Count, $date21));
    // $date1[] = 
    $date1_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel =1
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date1_a = mysql_fetch_array($date1_query);
    $date1 = $date1_a[0];
    $p1date1Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel =1
AND JailBreak = '0'
");
    $p1date1Count_a = mysql_fetch_array($p1date1Count_query);
    $p1date1Count = $p1date1Count_a[0];
    $date2_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE CurrentPlayerLevel =2
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date2_a = mysql_fetch_array($date2_query);
    $date2 = $date2_a[0];
    $p1date2Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel =2
AND JailBreak = '0'");
    $p1date2Count_a = mysql_fetch_array($p1date2Count_query);
    $p1date2Count = $p1date2Count_a[0];
    $date3_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel =3
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date3_a = mysql_fetch_array($date3_query);
    $date3 = $date3_a[0];
    $p1date3Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel =3
AND JailBreak = '0'");
    $p1date3Count_a = mysql_fetch_array($p1date3Count_query);
    $p1date3Count = $p1date3Count_a[0];
    $date4_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel =4
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date4_a = mysql_fetch_array($date4_query);
    $date4 = $date4_a[0];
    $p1date4Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE CurrentPlayerLevel =4
AND JailBreak = '0'");
    $p1date4Count_a = mysql_fetch_array($p1date4Count_query);
    $p1date4Count = $p1date4Count_a[0];
    $date5_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel =5
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date5_a = mysql_fetch_array($date5_query);
    $date5 = $date5_a[0];
    $p1date5Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE CurrentPlayerLevel =5
AND JailBreak = '0'");
    $p1date5Count_a = mysql_fetch_array($p1date5Count_query);
    $p1date5Count = $p1date5Count_a[0];
    $date6_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel =6
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date6_a = mysql_fetch_array($date6_query);
    $date6 = $date6_a[0];
    $p1date6Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel =6
AND JailBreak = '0'");
    $p1date6Count_a = mysql_fetch_array($p1date6Count_query);
    $p1date6Count = $p1date6Count_a[0];
    $date7_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel =7
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date7_a = mysql_fetch_array($date7_query);
    $date7 = $date7_a[0];
    $p1date7Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel =7
AND JailBreak = '0'");
    $p1date7Count_a = mysql_fetch_array($p1date7Count_query);
    $p1date7Count = $p1date7Count_a[0];
    $date8_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel =8
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date8_a = mysql_fetch_array($date8_query);
    $date8 = $date8_a[0];
    $p1date8Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel =8
AND JailBreak = '0'");
    $p1date8Count_a = mysql_fetch_array($p1date8Count_query);
    $p1date8Count = $p1date8Count_a[0];
    $date9_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel =9
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date9_a = mysql_fetch_array($date9_query);
    $date9 = $date9_a[0];
    $p1date9Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE CurrentPlayerLevel =9
AND JailBreak = '0'");
    $p1date9Count_a = mysql_fetch_array($p1date9Count_query);
    $p1date9Count = $p1date9Count_a[0];
    $date10_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel =10
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE JailBreak = '0' )
) *100, '%')
");
    $date10_a = mysql_fetch_array($date10_query);
    $date10 = $date10_a[0];
    $p1date10Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel =10
AND JailBreak = '0'");
    $p1date10Count_a = mysql_fetch_array($p1date10Count_query);
    $p1date10Count = $p1date10Count_a[0];
    $date11_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 11 and 15
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')
");
    $date11_a = mysql_fetch_array($date11_query);
    $date11 = $date11_a[0];
    $p1date11Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 11 and 15
AND JailBreak = '0'");
    $p1date11Count_a = mysql_fetch_array($p1date11Count_query);
    $p1date11Count = $p1date11Count_a[0];
    $date12_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 16 and 20
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')");
    $date12_a = mysql_fetch_array($date12_query);
    $date12 = $date12_a[0];
    $p1date12Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 16 and 20
AND JailBreak = '0'");
    $p1date12Count_a = mysql_fetch_array($p1date12Count_query);
    $p1date12Count = $p1date12Count_a[0];
    $date13_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 21 and 25
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')");
    $date13_a = mysql_fetch_array($date13_query);
    $date13 = $date13_a[0];
    $p1date13Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 21 and 25
AND JailBreak = '0'");
    $p1date13Count_a = mysql_fetch_array($p1date13Count_query);
    $p1date13Count = $p1date13Count_a[0];
    $date14_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 26 and 30
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')");
    $date14_a = mysql_fetch_array($date14_query);
    $date14 = $date14_a[0];
    $p1date14Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 26 and 30
AND JailBreak = '0'");
    $p1date14Count_a = mysql_fetch_array($p1date14Count_query);
    $p1date14Count = $p1date14Count_a[0];
    $date15_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 31 and 40
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')");
    $date15_a = mysql_fetch_array($date15_query);
    $date15 = $date15_a[0];
    $p1date15Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 31 and 40
AND JailBreak = '0'");
    $p1date15Count_a = mysql_fetch_array($p1date15Count_query);
    $p1date15Count = $p1date15Count_a[0];
    $date16_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 41 and 50
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')");
    $date16_a = mysql_fetch_array($date16_query);
    $date16 = $date16_a[0];
    $p1date16Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 41 and 50
AND JailBreak = '0'");
    $p1date16Count_a = mysql_fetch_array($p1date16Count_query);
    $p1date16Count = $p1date16Count_a[0];
    $date17_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 51 and 60
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')");
    $date17_a = mysql_fetch_array($date17_query);
    $date17 = $date17_a[0];
    $p1date17Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 51 and 60
AND JailBreak = '0'");
    $p1date17Count_a = mysql_fetch_array($p1date17Count_query);
    $p1date17Count = $p1date17Count_a[0];
    $date18_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 61 and 70
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')");
    $date18_a = mysql_fetch_array($date18_query);
    $date18 = $date18_a[0];
    $p1date18Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 61 and 70
AND JailBreak = '0'");
    $p1date18Count_a = mysql_fetch_array($p1date18Count_query);
    $p1date18Count = $p1date18Count_a[0];
    $date19_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 71 and 80
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')");
    $date19_a = mysql_fetch_array($date19_query);
    $date19 = $date19_a[0];
    $p1date19Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 71 and 80
AND JailBreak = '0'");
    $p1date19Count_a = mysql_fetch_array($p1date19Count_query);
    $p1date19Count = $p1date19Count_a[0];
    $date20_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 81 and 90
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  JailBreak = '0' )
) *100, '%')");
    $date20_a = mysql_fetch_array($date20_query);
    $date20 = $date20_a[0];
    $p1date20Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 81 and 90
AND JailBreak = '0'");
    $p1date20Count_a = mysql_fetch_array($p1date20Count_query);
    $p1date20Count = $p1date20Count_a[0];
    $date21_query = mysql_query("SELECT concat( (
(
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE  CurrentPlayerLevel between 91 and 100
AND JailBreak = '0' ) / (
SELECT count( DISTINCT deviceid )
FROM devildark_a 
WHERE JailBreak = '0' )
) *100, '%')");
    $date21_a = mysql_fetch_array($date21_query);
    $date21 = $date21_a[0];
    $p1date21Count_query = mysql_query("SELECT count( DISTINCT deviceid )
FROM devildark_a
WHERE  CurrentPlayerLevel between 91 and 100
AND JailBreak = '0'");
    $p1date21Count_a = mysql_fetch_array($p1date21Count_query);
    $p1date21Count = $p1date21Count_a[0];
    $CurrentPlayerLevel = array(json_encode($date));//等级分布

   
 $sql="REPLACE INTO report_nojailbreak_a (Pct1,  
  level1,
  Pct2,
  level2,
  Pct3,
  level3,
  Pct4,
  level4,
  Pct5,
  level5,
  Pct6,
  level6,
   Pct7,
  level7,
  Pct8,
  level8,
  Pct9,
  level9,
  Pct10,
  level10,
  Pct11_15,
  level11_15,
  Pct16_20,
  level16_20,
  Pct21_25,
  level21_25,
  Pct26_30,
  level26_30,
  Pct31_40,
  level31_40,
  Pct41_50,
  level41_50,
  Pct51_60,
  level51_60,
  Pct61_70,
  level61_70,
  Pct71_80,
  level71_80,
  Pct81_90,
  level81_90,
  Pct91_99,
  level91_99) 
                  VALUES('$date1','$p1date1Count','$date2','$p1date2Count','$date3','$p1date3Count','$date4',
'$p1date4Count','$date5','$p1date5Count','$date6','$p1date6Count','$date7',
'$p1date7Count','$date8','$p1date8Count','$date9','$p1date9Count','$date10',
'$p1date10Count','$date11','$p1date11Count','$date12','$p1date12Count','$date13',
'$p1date13Count','$date14','$p1date14Count','$date15','$p1date15Count','$date16',
'$p1date16Count','$date17','$p1date17Count','$date18','$p1date18Count','$date19',
'$p1date19Count','$date20','$p1date20Count','$date21','$p1date21Count')";
$query= @mysql_query($sql,$connection) or die(mysql_error());  


?>
